import uiautomator2 as u2
from adbutils import adb

# device_ip = 'e0edbd001403053'
device_1 = '29002590532e0032'
# device_1 = '00000000d5328bbf'
device_2 = '29002590532e0032'
# device_3 = 'bc527fe4'
# device_ip = '10.10.113.54:5555'
d_one = u2.connect(device_1)
d_one_device = adb.device(serial=device_1)
# d_two = u2.connect(device_2)
# d_two_device = adb.device(serial=device_2)

# device_info = {"d_one": d_one, "d_two": d_two}com.qiyi.video.iv
# adb_device = adb.device(serial=device_ip)
# adb_device.root()

if __name__ == '__main__':
    # d_one.app_start("com.qiyi.video.iv")
    # d_one.app_start("com.arcvideo.car.iqy.video")
    # adb_device.root()
    # adb_device.shell([r"sendevent /dev/input/event0 1 353 1", r"sendevent /dev/input/event0 0 0 0"])
    # adb_device.shell(r"sendevent /dev/input/event0 1 353 1")
    # res = adb_device.shell("< test.txt")
    # res = adb_device.shell("./data/test.sh")
    # res = adb_device.shell(
    #     "su & sendevent /dev/input/event0 1 353 1 & sendevent /dev/input/event0 0 0 0 & echo 'down' & sleep 3 & sendevent /dev/input/event0 1 353 0 & sendevent /dev/input/event0 0 0 0 & echo 'up'")
    # print(res)
    # res = d_one.app_current()
    # bounds = d_one(resourceId="立即登录").info
    # # print(res)
    # d_two_device.sync.push("/Users/only/Desktop/工作文档/DH/path_code/gitee_code/DH_Auto/Outputs/Screenshots/2024-07-10 16_34_10_保存登录二维码.jpg","/sdcard/AAA/333.jpg")
    # pass
    res = d_one.dump_hierarchy()
    # for each in d_one(text="无服务"):
    #     res=each.info
    #     print(res)
    # res=d_one(text="世界历史").info
    # print(res)
    # res=d_one.xpath("//*[@text='推荐' and @display-id='0']").info
    # d_one.xpath("//*[@text='世界历史']").click()
    # d_one(text="Settings").screenshot()
    # d_one.swipe()
    # d_one(text="音乐馆").click()
    # d_one.click()
    # print(d_one(text="无服务").info)
    # d_one(text="电视剧").click()
    # pass
    jsonres={'results': [{'text': 'OIYI', 'confidence': 0.7520898580551147, 'coordinates': [[55, 59], [95, 59], [95, 75], [55, 75]]}, {'text': '爱奇艺', 'confidence': 0.9608810851870946, 'coordinates': [[98, 43], [195, 43], [195, 87], [98, 87]]}, {'text': '起追剧吧', 'confidence': 0.993198037147522, 'coordinates': [[215, 123], [337, 123], [337, 161], [215, 161]]}, {'text': '前往爱奇艺', 'confidence': 0.9755181454623447, 'coordinates': [[189, 175], [339, 175], [339, 215], [189, 215]]}, {'text': '进入应用', 'confidence': 0.7191875576972961, 'coordinates': [[279, 265], [415, 265], [415, 307], [279, 307]]}]}
    print(res)